<html xmlns="http://www.w3.org/1999/xhtml"  
     xmlns:h="http://java.sun.com/jsf/html"      
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:r="http://ricchieri.com/facelets"
     xmlns:p="http://primefaces.org/ui">  
 <h:head></h:head>  
 <h:body>
 	<ui:composition template="../../templates/commonLayoutUsers.xhtml">
 	<ui:define name="title">#{msg.titleUser}</ui:define>
		<ui:define name="content">
		
		     <h:form id="searchUserForm">
		     		<p:messages showDetail="false" autoUpdate="true" closable="false" severity="info"/>          
		     		<h2>#{msg.searchuser}</h2> 
			     	<h:panelGrid columns="2">
			     		<h:outputLabel for="firstName" value="#{msg.first_name}" />
			     		<p:inputText id="firstName" value="#{searchUserMB.userFilter.firstName}"/>
			     		
			     		<h:outputLabel for="lastName" value="#{msg.last_name}" />  
					    <p:inputText id="lastName" value="#{searchUserMB.userFilter.lastName}" />
			            
			            <h:outputLabel for="documentType" value="#{msg.documentType}"/>
			     		<p:selectOneMenu id="documentType" value="#{searchUserMB.userFilter.documentType}">
							<f:selectItem itemLabel="#{msg.defaultComboValue}" itemValue="" />
			                <f:selectItems value="#{searchUserMB.documents}" />   
			            </p:selectOneMenu> 
			            
			     		<h:outputLabel for="dni" value="#{msg.documentNum}" />
					    <p:inputText id="dni" value="#{searchUserMB.userFilter.dni}" onkeypress="javascript:return isAlphanumericKey(event);"/>
			            
			            <h:outputLabel for="number" value="#{msg.phone_number}" />
			     		<p:inputText id="number" value="#{searchUserMB.userFilter.phoneNumber}" onkeypress="if(event.which &lt; 48 || event.which &gt; 57) return false;"/>
			     					
			     		<h:outputLabel for="email" value="#{msg.email}" />
			     		<p:inputText id="email" value="#{searchUserMB.userFilter.email}"/>

					</h:panelGrid>
					<h:panelGrid columns="2" style="margin-top:10px; text-align:center">
		     			<r:commandLinkCustom id="reset" action="#{searchUserMB}" method="reset" icon="icon-eraser" message="#{msg.resetButton}"/>
	     				<r:commandLinkCustom id="search" action="#{searchUserMB}" method="search" icon="icon-search" message="#{msg.searchButton}"/>
		     	 	</h:panelGrid>
		     	 	
		     	 	<p:blockUI block="userTable" trigger="userTable">  
				        #{msg.loading}<br />  
				        <p:graphicImage value="/images/ajax-loader.gif"/>  
				    </p:blockUI>
		     	 	<p:dataTable var="user" value="#{searchUserMB.userLazyDataModel}" 
		     	 		style="padding-top:15px" paginator="true" lazy="true" id="userTable"
		     	 		rows="10"
		     	 		paginatorPosition="bottom" emptyMessage="#{msg.noRecordsFound}">
		 
		 		 		<p:column headerText="#{msg.full_name}" style="width:30%">  
			            	<h:outputText value="#{user.getFullName()}" />   
		        		</p:column> 
		 
		 				<p:column headerText="#{msg.documentType}" style="width:7%">  
			            	<h:outputText value="#{searchUserMB.obtainDescription(user.documentType.description)}" />   
		        		</p:column> 
		        		
				        <p:column headerText="#{msg.documentNum}" style="width:20%"  sortBy="#{user.dni}">  
			            	<h:outputText value="#{user.dni}" />   
		        		</p:column> 
		        		
		        		<p:column headerText="#{msg.autorized}" style="width:10%"  sortBy="#{user.autorized}">  
			            	<h:outputText value="#{searchUserMB.obtainBooleanDescription(user.autorized)}" />   
		        		</p:column> 
		        		
		        		<p:column headerText="#{msg.actions}" style="width:40%">
		        			<center>
			        			<h:commandLink action="#{searchUserMB.viewUser(user)}" ajax="false" process="@form">
		        					<i class="icon-zoom-in icon-2x color-zoom"></i>
		        				</h:commandLink>
		        				<r:space/><r:space/>
		        				
			        			<h:commandLink action="#{searchUserMB.editUser(user)}"  ajax="false" process="@form">
		        					<i class="icon-edit icon-2x color-edit"></i>
		        				</h:commandLink>
								<r:space/><r:space/>
								
			        			<p:commandLink oncomplete="deleteUser.show();" action="#{searchUserMB.showDialog(user)}">
			        				<i class="icon-remove-sign icon-2x color-delete"></i>
		        				</p:commandLink>
		        				<r:space/><r:space/>
		        				
			        			<p:commandLink oncomplete="bloqUser.show();" action="#{searchUserMB.showDialog(user)}" rendered="#{user.autorized}">
			        				<i class="icon-lock icon-2x color-lock"></i>
		        				</p:commandLink>

		        				<p:commandLink oncomplete="unlockUser.show();" action="#{searchUserMB.showDialog(user)}" rendered="#{not user.autorized}">
			        				<i class="icon-unlock icon-2x color-lock"></i>
		        				</p:commandLink>
		        				<r:space/><r:space/> 
		        				
		        				<p:commandLink oncomplete="confirmDialogReservationBlock.show();" action="#{searchUserMB.showDialog(user)}" rendered="#{searchUserMB.showBlock(user)}">
			        				<span class="icon-stack" style="vertical-align: -16%; display: inline-block;">
									  <i class="icon-truck"></i>
									  <i class="icon-ban-circle icon-stack-base color-delete"></i>
									</span>
		        				</p:commandLink>
		        				
		        				<p:commandLink oncomplete="confirmDialogReservationUnblock.show();" action="#{searchUserMB.showDialog(user)}" rendered="#{searchUserMB.showUnblock(user)}">
									<i class="icon-truck icon-2x"></i>
		        				</p:commandLink>
	        				
		        			</center>
		        		</p:column>  
				    </p:dataTable>
		     	 	
		     	 	<p:confirmDialog id="confirmDialogDel" message="#{msg.deleteMessage}"  
				                header="#{msg.deleteProcessHeader}" severity="alert" widgetVar="deleteUser"> 
				    	<center> 
				    		<p:commandButton id="confirmdelete" value="#{msg.yesMessage}" oncomplete="deleteUser.hide()" action="#{searchUserMB.delete()}" update="@form" partialSubmit="true" process="@form" />	
				        	<p:commandButton id="declinedelete" value="#{msg.noMessage}" oncomplete="deleteUser.hide()" action="#{searchUserMB.unselect()}"/>  
				    	</center>       
				    </p:confirmDialog>  
				    
				    <p:confirmDialog id="confirmDialogBloq" message="#{msg.unauthorizedMessage}"  
				                header="#{msg.unauthorizedProcessHeader}" severity="alert" widgetVar="bloqUser">  
				        <center>
				        	<p:commandButton id="confirmeunauthorized" value="#{msg.yesMessage}" oncomplete="bloqUser.hide()" action="#{searchUserMB.unauthorize()}" update="@form" partialSubmit="true" process="@form" />
				        	<p:commandButton id="declineunauthorized" value="#{msg.noMessage}" oncomplete="bloqUser.hide()" action="#{searchUserMB.unselect()}"/>  
				    	</center>              
				    </p:confirmDialog>
				    
				    <p:confirmDialog id="confirmDialogDesbBloq" message="#{msg.authorizedMessage}"  
				                header="#{msg.authorizedProcessHeader}" severity="alert" widgetVar="unlockUser">  
				        <center>
				        	<p:commandButton id="confirmauthorized" value="#{msg.yesMessage}" oncomplete="unlockUser.hide()" action="#{searchUserMB.authorize()}" update="@form" partialSubmit="true" process="@form" />
				        	<p:commandButton id="declineauthorized" value="#{msg.noMessage}" oncomplete="unlockUser.hide()" action="#{searchUserMB.unselect()}"/>  
				    	</center>              
				    </p:confirmDialog>
				    
				    <p:dialog id="confirmDialogReservationBlock" header="#{msg.blockReservationHeader}" widgetVar="confirmDialogReservationBlock" showEffect="clip" hideEffect="clip" maximizable="false" minimizable="false" resizable="false">  
				       	<h:panelGrid columns="1" style="padding-bottom: 10px">  
				       		<h:outputText value="#{msg.blockReservationMessage}" />    
				       	</h:panelGrid>  
				       	
				       	<h:panelGrid columns="1" id="blockPanel">  
					       	<h:outputText value="#{msg.blockMotive}" />   
					       	<p:inputTextarea rows="7" style="width:98%" id="message" columns="30"
						       autoResize="false" value="#{searchUserMB.blockMotive}"
						       title="#{component.valid ? '' : searchUserMB.getErrorMessage(component.clientId)}"
						       maxlength="100"/>
					       	<p:message id="messageMsg" for="message"/>
				       	</h:panelGrid>
				       	<div style="text-align: center;padding-top: 10px">
					        <p:commandButton id="confirmeblock" value="#{msg.yesMessage}" oncomplete="handleRequest(xhr, status, args)" action="#{searchUserMB.blockUser()}" update="blockPanel"/>
					        <p:commandButton id="declineblock" value="#{msg.noMessage}" oncomplete="confirmDialogReservationBlock.hide()" action="#{searchUserMB.unselect()}"/>
				    	</div>         
				    </p:dialog>
				    
				    <p:confirmDialog id="confirmDialogReservationUnblock" message="#{msg.unblockReservationMessage}"  
				                header="#{msg.unblockReservationHeader}" severity="alert" widgetVar="confirmDialogReservationUnblock">  
				        <center>
				        	<p:commandButton id="confirmunblock" value="#{msg.yesMessage}" oncomplete="confirmDialogReservationUnblock.hide()" action="#{searchUserMB.unblockUser()}" update="@form" partialSubmit="true" process="@form" />
				        	<p:commandButton id="declineunblock" value="#{msg.noMessage}" oncomplete="confirmDialogReservationUnblock.hide()" action="#{searchUserMB.unselect()}"/>  
				    	</center>              
				    </p:confirmDialog>
				    <script type="text/javascript">
						function handleRequest(xhr, status, args) {
					        if(args.validationFailed || !args.isValid) {
								return;
					        } else {
					        	confirmDialogReservationBlock.hide();
					        }
					    }
					</script>
				    
		     </h:form> 
    	 </ui:define>
     </ui:composition>    
</h:body>
</html> 